<template>
  <div id="homeai" class="homeai">
	  <group class="groupai">
		  <group class="todayActivityGroup">
			  <div style="margin-top: 10px; margin-bottom: 10px">
				  <span class="blockTitle">智能助理</span>
			  </div>
		  </group>

		  <group title="近7天未安排课" class="subgroupai">
			  <cell v-if="userList.length == 0" title="近7天，你的学员都安排了课，非常好！">
			  </cell>
			  <cell v-else class="subgroupaiCell" v-for="item in userList" @click.native="jumpTo(item.id)" :title=item.name>
				  <img slot="icon" width="50" style="display:block;margin-right:5px;" src="@/assets/profile/default_header.svg">
				  <span v-if="item.status == 0" style="background-color: red; color: white">试听学员</span>
			  </cell>
		  </group>
		  <group title="待刷课时" class="subgroupai">
			  <cell class="subgroupaiCell" :title=pendingConfirmMsg @click.native="jumpToPendingConfirm()">
			  </cell>
		  </group>
		  <group title="待回馈" class="subgroupai" @click.native="jumpToPendingFeedback()">
			  <cell class="subgroupaiCell" :title=pendingFeedbackMsg>
			  </cell>
		  </group>
		  <!--<group title="课消排名" class="subgroupai">
			  <cell class="subgroupaiCell" :title=teacherRankMsg>
			  </cell>
		  </group>-->
	  </group>
  </div>
</template>

<script>
	import NetWorking from '@/utils/networking'
  import {Group, Cell} from 'vux'
  export default {
    name: "homeai",
    components:{
      Group,
      Cell
    },
    data() {
      return {
      	userList: '',
	      pendingConfirm: '',
	      pendingFeedback: '',
	      teacherRank: '',
	      pendingConfirmMsg: '',
	      pendingFeedbackMsg: '',
	      teacherRankMsg: ''
      }
    },
	  created: function () {
		  let _this = this
		  NetWorking.doGet(
			  'ai/getAIModel',
			  null,
			  null
		  ).then(
			  response => {
				  let rs = response.data
				  if(rs.error_code == 0){
				  	_this.userList = rs.ai_model.sysCustomerList
					  _this.pendingConfirm = rs.ai_model.teacherPendingConfirmNum
					  _this.pendingFeedback = rs.ai_model.teacherPendingFeedbackNum
					  _this.teacherRank = rs.ai_model.teacherRank
				  }else{
				  	alert(rs.error_message)
				  }
			  }
		  )
	  },
	  watch: {
		  pendingConfirm: function () {
		  	if(this.pendingConfirm > 0){
				  this.pendingConfirmMsg = '你有' + this.pendingConfirm + '节待刷课，别忘了及时刷课'
			  }else{
				  this.pendingConfirmMsg = '没有待刷的课，很好，继续保持'
			  }

		  },
		  pendingFeedback: function () {
			  if(this.pendingFeedback > 0){
				  this.pendingFeedbackMsg = '你有' + this.pendingFeedback + '节待反馈，好的反馈可以提高满意度哦'
			  }else{
				  this.pendingFeedbackMsg = '没有待反馈的课，很好，继续保持'
			  }
		  },
		  teacherRank: function () {
		  	if(this.teacherRank == null){
				  this.teacherRankMsg = '你还未有数据，快去开课吧'
			  }else if(this.teacherRank.id > 0 && this.teacherRank.id < 3){
			  	this.teacherRankMsg = '你本月消课' + this.teacherRank.value + '节，排名第' + this.teacherRank.id + '，很棒，继续保持'
			  }else{
				  this.teacherRankMsg = '你本月消课' + this.teacherRank.value + '节，排名第' + this.teacherRank.id + '，加油'
			  }
		  }
	  },
	  methods: {
		  jumpTo: function (id) {
			  //组件间传递参数
			  this.$router.push({ name: 'customerDetails', params: { id: id }})
		  },
		  jumpToPendingConfirm: function () {
			  //组件间传递参数
			  //this.$router.push({ name: 'lesson', params: {page: 'getPendingConfirm'}})
			  this.$router.push({ path: '/lesson', query: {page: 'getPendingConfirm'}})
		  },
		  jumpToPendingFeedback: function () {
			  //组件间传递参数
			  this.$router.push({ path: '/lesson', query: {page: 'getPendingFeedback'}})
		  }
	  }
  }
</script>

<style>
	.homeai {
		margin-bottom: 10px;
	}

	.groupai > .weui-cells__title{
		font-weight: bold;
		font-size: 18px;
		padding-left: 5px;
		color: black;
	}

	.groupai > .weui-cells {
		margin-top: 0em !important;
	}

  .subgroupai{
    margin-bottom: 20px;
  }

  .subgroupaiCell{
	  padding: 0px 15px!important;
  }

  .subgroupai > .weui-cells__title{
	  font-weight: bold;
	  font-size: 14px;
	  color: gray;
  }

  .subgroupai > .weui-cells > .weui-cell {
	  padding: 0px 15px!important;
  }
</style>
